#pragma once

#include "PackageMerge.h"

#include "Package.h"

namespace uml {

void PackageMerge::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    DirectedRelationship::fromJson(json, errorList);
    mergedPackage_ = JsonSerializable::create<Package>(json.value("mergedPackage"), errorList);

    receivingPackage_ = JsonSerializable::create<Package>(json.value("receivingPackage"), errorList);

}

void PackageMerge::toJson(QJsonObject& json) {
    DirectedRelationship::toJson(json);
    if (mergedPackage_) {
        QJsonObject mergedPackage_json;
        mergedPackage_->toJson(mergedPackage_json);
        json.insert("mergedPackage", mergedPackage_json);
    }
    if (receivingPackage_) {
        QJsonObject receivingPackage_json;
        receivingPackage_->toJson(receivingPackage_json);
        json.insert("receivingPackage", receivingPackage_json);
    }
}

/// <summary>
/// mergedPackage getter
/// References the Package that is to be merged with the receiving package of the
/// PackageMerge.
/// </summary>
shared_ptr<Package> PackageMerge::mergedPackage() const {
    return mergedPackage_;
}

/// <summary>
/// mergedPackage setter
/// References the Package that is to be merged with the receiving package of the
/// PackageMerge.
/// </summary>
void PackageMerge::setMergedPackage(shared_ptr<Package> value) {
    mergedPackage_ = value;
}

/// <summary>
/// receivingPackage getter
/// References the Package that is being extended with the contents of the merged
/// package of the PackageMerge.
/// </summary>
shared_ptr<Package> PackageMerge::receivingPackage() const {
    return receivingPackage_;
}

/// <summary>
/// receivingPackage setter
/// References the Package that is being extended with the contents of the merged
/// package of the PackageMerge.
/// </summary>
void PackageMerge::setReceivingPackage(shared_ptr<Package> value) {
    receivingPackage_ = value;
}

} // namespace uml
